import { request } from "@/http/axios"
import type { UserItem, GetUsersRequestData, GetUsersResponseData, CreateUserRequestData, UpdateUserRequestData, ResetPasswordRequestData } from "./type"

/** 获取当前登录用户详情 */
export function getUserInfoApi() {
  return request<UserItem>({
    url: "auth/me",
    method: "get"
  })
}

/** 获取用户列表 */
export function getUsersApi(params?: GetUsersRequestData) {
  return request<GetUsersResponseData>({ // Expects GetUsersResponseData
    url: "users",
    method: "get",
    params // Pass pagination parameters
  })
}

/** 创建用户 */
export function createUserApi(data: CreateUserRequestData) {
  return request({
    url: "users",
    method: "post",
    data
  })
}

/** 更新用户信息 */
export function updateUserApi(id: string, data: UpdateUserRequestData) {
  return request({
    url: `users/${id}`,
    method: "put",
    data
  })
}

/** 删除用户 */
export function deleteUserApi(id: string) {
  return request({
    url: `users/${id}`,
    method: "delete"
  })
}

/** 重置用户密码 */
export function resetUserPasswordApi(id: string, data: ResetPasswordRequestData) {
  return request({
    url: `users/${id}/reset-password`,
    method: "post",
    data
  })
}
